package javabase.base.client10.deep.client4;

import javabase.base.client10.deep.Address;
import javabase.base.client10.deep.User;
import org.apache.commons.lang3.SerializationUtils;
import org.junit.Test;

/**
 * @author chengshuai
 * @date 2021/5/2 13:05
 *
 * https://www.cnblogs.com/xinruyi/p/11537963.html
 */
public class Client4 {


    /**
     * Apache Commons Lang序列化
     * 不需要序列化接口和克隆接口
     */
    @Test
    public void f1() {
        Address address = new Address("杭州", "中国");
        User user = new User("大山", address);

        // 使用Apache Commons Lang序列化进行深拷贝
        User copyUser = (User) SerializationUtils.clone(user);
        // 修改源对象的值
        user.getAddress().setCity("深圳");
        // 检查两个对象的值不同
        System.out.println(user.getAddress().getCity());
        System.out.println(copyUser.getAddress().getCity());
    }


}
